home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 June / PersonalComputerWorld-June2009-CoverdiscCD.iso / Software / Freeware / Firebug 1.3.3 / firebug-1.3.3-fx.xpi / content / firebug / traceConsole.js < prev    next >
Encoding:
Text File  |  2009-02-19  |  4.9 KB  |  164 lines

  1. /* See license.txt for terms of usage */
  2.  
  3. // ************************************************************************************************
  4. // Shorcuts and Services
  5.  
  6. const Cc = Components.classes;
  7. const Ci = Components.interfaces;
  8.  
  9. const traceService = Cc["@joehewitt.com/firebug-trace-service;1"].getService(Ci.nsIObserverService);
  10. const hiddenWindow = Cc["@mozilla.org/appshell/appShellService;1"].getService(Ci.nsIAppShellService).hiddenDOMWindow;
  11.  
  12. const PrefService = Cc["@mozilla.org/preferences-service;1"];
  13. const prefs = PrefService.getService(Ci.nsIPrefBranch2);
  14. const prefService = PrefService.getService(Ci.nsIPrefService);
  15.  
  16. var gFindBar;
  17.  
  18. const reDBG = /extensions\.([^\.]*)\.(DBG_.*)/;
  19. const reDBG_FBS = /DBG_FBS_(.*)/;
  20.  
  21. // The lib.js isn't included in this window so, define the global here. 
  22. // It'll be initialized from window parameters (see initialize method).
  23. var FBL;
  24.  
  25. // ************************************************************************************************
  26. // Trace Window Implementation
  27.  
  28. var TraceConsole =
  29. {
  30.     modules: [],
  31.  
  32.     initialize: function()  
  33.     {
  34.         var args = window.arguments[0];
  35.         FBL = args.FBL;
  36.         Firebug = args.Firebug; 
  37.  
  38.         // Get pref domain is used for message filtering. Only logs that belong
  39.         // to this pref-domain will be displayed.
  40.         this.prefDomain = args.prefDomain; 
  41.         window.title = FBL.$STR("title.Tracing") + ": " + this.prefDomain;
  42.  
  43.         // Initialize root node of the trace-console window.
  44.         var consoleFrame = document.getElementById("consoleFrame");
  45.         this.consoleNode = consoleFrame.contentDocument.getElementById("panelNode-traceConsole");
  46.         this.logs = Firebug.TraceModule.CommonBaseUI.initializeContent(this.consoleNode, this.prefDomain);
  47.  
  48.         // Register listeners and observers
  49.         traceService.addObserver(this, "firebug-trace-on-message", false);
  50.  
  51.         gFindBar = document.getElementById("FindToolbar");
  52.  
  53.         // Notify listeners
  54.         Firebug.TraceModule.onLoadConsole(window, this.consoleNode);
  55.         this.registerModule(Firebug.TraceModule);
  56.  
  57.         // Make sure the UI is localized.
  58.         this.internationalizeUI();
  59.     },
  60.  
  61.     internationalizeUI: function()
  62.     {
  63.         var buttons = ["clearConsole", "findConsole", "separateConsole", 
  64.             "restartFirefox", "closeFirefox"];
  65.  
  66.         for (var i=0; i<buttons.length; i++)
  67.         {
  68.             var element = document.getElementById(buttons[i]);
  69.             FBL.internationalize(element, "label");
  70.             FBL.internationalize(element, "tooltiptext");
  71.         }
  72.     },
  73.  
  74.     shutdown: function()
  75.     {
  76.         traceService.removeObserver(this, "firebug-trace-on-message");
  77.  
  78.         // Notify listeners
  79.         for (var i=0; i<this.modules.length; ++i)
  80.             this.modules[i].onUnloadConsole(window);
  81.     },
  82.  
  83.     registerModule: function(traceModule)
  84.     {
  85.         this.modules.push(traceModule);
  86.     },
  87.  
  88.     unregisterModule: function(module)
  89.     {
  90.         for (var i=0; i<this.modules.length; ++i) {
  91.             if (this.modules[i] == module) {
  92.                 this.modules.splice(i, 1);
  93.                 break;
  94.             }
  95.         }
  96.     },
  97.  
  98.     // nsIObserver
  99.     observe: function(subject, topic, data)
  100.     {
  101.         if (topic == "firebug-trace-on-message")
  102.         {
  103.             // Display messages only with "firebug.extensions" type.
  104.             var messageInfo = subject.wrappedJSObject;
  105.  
  106.             // If the message type isn't specified, use Firebug's pref domain as the default.
  107.             if (!messageInfo.type)
  108.                 messageInfo.type = "extensions.firebug";
  109.  
  110.             if (messageInfo.type != this.prefDomain)
  111.                 return;
  112.  
  113.             this.dump(new Firebug.TraceModule.TraceMessage(
  114.                 messageInfo.type, data, messageInfo.obj));
  115.         }
  116.     },
  117.  
  118.     // Message dump
  119.     dump: function(message)
  120.     {
  121.         // Notify listeners
  122.         for (var i=0; i<this.modules.length; ++i)
  123.             this.modules[i].onDump(message);
  124.  
  125.         Firebug.TraceModule.dump(message, this.logs.firstChild);
  126.     },
  127.  
  128.     dumpSeparator: function()
  129.     {
  130.         Firebug.TraceModule.MessageTemplate.dumpSeparator(
  131.             this.logs.firstChild);
  132.     },
  133.  
  134.     // Trace console toolbar commands
  135.     onClearConsole: function()
  136.     {
  137.         var tbody = this.logs.firstChild;
  138.         while (tbody.firstChild)
  139.             tbody.removeChild(tbody.lastChild);
  140.     },
  141.  
  142.     onSeparateConsole: function()
  143.     {
  144.         Firebug.TraceModule.MessageTemplate.dumpSeparator(this.logs.firstChild);
  145.     },
  146.  
  147.     onSaveToFile: function()
  148.     {
  149.     },
  150.  
  151.     onRestartFirefox: function()
  152.     {
  153.         Cc["@mozilla.org/toolkit/app-startup;1"].getService(Ci.nsIAppStartup).
  154.             quit(Ci.nsIAppStartup.eRestart | Ci.nsIAppStartup.eAttemptQuit);
  155.     },
  156.  
  157.     onExitFirefox: function()
  158.     {
  159.         goQuitApplication();
  160.     }
  161. };
  162.  
  163. // ************************************************************************************************
  164.